package com.atguigu.guilimall.search.controller;

import com.atguigu.guilimall.search.service.MallSearchService;
import com.atguigu.guilimall.search.vo.SearchParamVo;
import com.atguigu.guilimall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @DESCRIPTION: 页面搜索
 * @author: zr
 * @DATE: 2022/12/17 21:49
 */
@Controller
public class SearchController {
    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping("/list.html")
    public String listPage(SearchParamVo searchParamVo, Model model, HttpServletRequest request) {
        // 根据从页面传递过来的参数 到es中查询商品 并放入model
        searchParamVo.set_queryString(request.getQueryString());
        SearchResultVo searchResultVo = mallSearchService.search(searchParamVo);
        model.addAttribute("result", searchResultVo);
        return "list";
    }
}
